﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace btnet.pages
{
    public partial class edit_queued_notifications : CommonPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            Bug_Util.do_not_cache(Response);

            security = new Security();
            security.check_security(HttpContext.Current, Security.MUST_BE_ADMIN);

            if (Request.QueryString["ses"] != (string)Session["session_cookie"])
            {
                Response.Write("session in URL doesn't match session cookie");
                Response.End();
            }

            if (Request.QueryString["actn"] == "delete")
            {
                sql = @"delete from queued_notifications where qn_status = N'not sent'";
                DbUtil.execute_nonquery(sql);
            }
            else if (Request.QueryString["actn"] == "reset")
            {
                sql = @"update queued_notifications set qn_retries = 0 where qn_status = N'not sent'";
                DbUtil.execute_nonquery(sql);
            }
            else if (Request.QueryString["actn"] == "resend")
            {
                // spawn a worker thread to send the emails
                System.Threading.ThreadStart worker = new System.Threading.ThreadStart(btnet.Bug.threadproc_notifications);
                System.Threading.Thread thread = new System.Threading.Thread(worker);
                thread.Start();
            }


            Response.Redirect("notifications.aspx");
        }
    }
}
